<template>
  <div class="alarmConfiguration zy-content">
    <search :columns="searchData" @getSearch="getSearch(arguments)"></search>
    <div class="list-layout mt16">
      <!-- 批量删除 批量导出  批量导入 下载模板 新增-->
      <div class="btns clear">
        <span class="title">{{ $t("common.listInformation") }}</span>
        <!-- <Button @click="createfaultCodeShowH">{{ $t('common.New') }}</Button> -->
        <!-- <Button @click="delFaultCodeShowClick">{{ $t('common.batchDelete') }}</Button> -->
        <Button @click="exportTemplateClick">
          {{ $t("common.batchExport") }}
        </Button>
        <!-- <Button @click="importExcelShow">{{ $t('common.Import') }}</Button> -->
        <!-- <Button @click="exportTemplate">{{ $t('common.Download') }}</Button> -->
        <!-- <Button
          @click="getTableColumns(columns)"
        >{{ handleContextMenuStatus ? $t("显示操作栏") : $t("隐藏操作栏") }}</Button> -->
      </div>
      <!-- 表格 -->
      <div class="tableContent">
        <Table
          class="resizable-table"
          border
          @on-column-width-resize="onColumnWidthResize"
          :columns="columnsList"
          ellipsis
          ref="selection"
          stripe
          :data="dataArr"
          @on-selection-change="onSelectChange"
        >
          <template slot-scope="{ row }" slot="action">
            <span class="operationBtn" @click="createfaultCodeShowH(row)">
              <i class="iconfont zy-common-bianji"></i>
              {{ $t("common.Edit") }}
            </span>
            <span class="operationBtn" @click="delPrrShowH(row)">
              <i class="iconfont zy-common-shanchu"></i>
              {{ $t("common.Delete") }}
            </span>
          </template>
        </Table>
      </div>
      <!-- 分页 -->
      <div class="pageWrap mt16">
        <pageLeftTitle :total="total" :selected="delIds.length" />
        <Page
          :total="total"
          :page-size="pageSize"
          :page-size-opts="pageSizeOption"
          :current="pageNum"
          @on-change="changePageNum"
          @on-page-size-change="changePageSize"
          show-sizer
          show-total
        />
      </div>
    </div>
  </div>
</template>

<script>
import search from "@/components/curd/searchList.vue";
import fileDownload from "js-file-download";
import toggleTableOperation from "@/mixins/toggleTableOperation";
export default {
  name: "machineAdjustmentRecord", //仓库配置
  components: { search },
  mixins: [toggleTableOperation],
  data() {
    return {
      loading: false,
      searchParams: {},
      pageNum: 1,
      pageSize: 10,
      total: 0,
      searchData: [
        {
          title: "功能位置",
          key: "installPosition",
          type: "cascader",
          dicUrl: "/basic/organization/findListByToken?level=0",
          params: {
            label: "name",
            value: "code",
            children: "children"
          }
        },
        {
          title: "设备编号",
          key: "deviceCode"
        },
        {
          title: "工单号",
          key: "workCode"
        },
        {
          title: "调机开始时间",
          key: "ferryTime",
          type: "daterange",
          // format: "yyyy-MM-dd HH:mm:ss",
          // span:8,
        },
        {
          title: "产品名称",
          key: "materialName"
        },
        {
          title: "调机开始人",
          key: "ferryFlightMan"
        }
      ],
      columns: [
        {
          title: "功能位置",
          key: "installPositionName",
          minWidth: 130,
          align: "center",
          resizable: true
        },
        {
          title: "设备编号",
          key: "deviceCode",
          minWidth: 130,
          align: "center",
          resizable: true
        },
        {
          title: "模具编号",
          key: "moldCode",
          minWidth: 130,
          align: "center",
          resizable: true
        },
        {
          title: "工单号",
          key: "workCode",
          minWidth: 150,
          align: "center",
          resizable: true
        },
        {
          title: "产品编号",
          key: "materialCode",
          minWidth: 130,
          align: "center",
          resizable: true
        },
        {
          title: "产品名称",
          key: "materialName",
          minWidth: 150,
          align: "center",
          resizable: true
        },
        // {
        //   title: "调机报废数量",
        //   key: "inventoryQuantity",
        //   minWidth: 150,
        //   align: "center",
        //   resizable: true
        // },
        // {
        //   title: "调机报废重量(kg)",
        //   key: "--",
        //   minWidth: 150,
        //   align: "center",
        //   resizable: true
        // },
        {
          title: "开始时间",
          key: "ferryFlightTime",
          minWidth: 150,
          align: "center",
          resizable: true
        },
        {
          title: "调机开始人",
          key: "ferryFlightMan",
          minWidth: 150,
          align: "center",
          resizable: true
        },
        {
          title: "结束时间",
          key: "ferryFlightEndTime",
          minWidth: 150,
          align: "center",
          resizable: true
        },
        {
          title: "调机结束人",
          key: "ferryFlightMan",
          minWidth: 180,
          align: "center",
          resizable: true
        },
        {
          title: "调机时长(min)",
          key: "ferryFlightDuration",
          minWidth: 180,
          align: "center",
          resizable: true
        }
      ],
      dataArr: [],
      pageSizeOption: [10, 20, 30, 40],
      delIds: []
    };
  },
  mounted() {
    this.getTableColumnsWidth(this.columns);
    this.searchList();
  },
  methods: {
    getSearch(arg) {
      this.searchParams = JSON.parse(JSON.stringify(arg[0]));
      const { installPosition,ferryTime } = this.searchParams;
      if (installPosition && installPosition.length !== 0) {
        this.searchParams.installPosition = installPosition.at(-1);
      } else delete this.searchParams.installPosition;
      if (ferryTime && ferryTime.length !== 0) {
        this.searchParams.startTime= ferryTime[0]
        this.searchParams.endTime= ferryTime[1]
        delete this.searchParams.ferryTime
      }
      this.pageNum=1;
      this.searchList();
    },
    reset() {
      this.searchParams = {};
      this.changeNum();
    },
    //分页
    changeNum() {
      this.pageNum = 1;
      this.searchList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.searchList();
    },

    changePageNum(val) {
      this.pageNum = val;
      this.searchList();
    },
    //查询列表
    searchList() {
      let params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        ...this.searchParams
      };
      this.axios({
        method: "post",
        // url: "/dms/productionWork/queryFFWorkRecordList",
        url: "/dms/productionWork/queryFFWorkRecordList",
        data: params
      }).then(res => {
        if (res.code === 200) {
          this.dataArr = res.data.records;
          this.total = res.data.total;
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true
          });
        }
      });
    },
    //导出
    exportTemplateClick() {
      let params = {
        delIds: this.delIds
      };
      for (let key in this.searchParams) {
        if (this.searchParams[key]) {
          this.$set(params, key, this.searchParams[key]);
        }
      }
      const filName = "调机记录";
      this.axios({
        url: "/dms/productionWork/exportFFWorkRecordList",
        method: "post",
        data: params,
        responseType: "blob"
      }).then(res => {
        fileDownload(res, filName + ".xlsx");
      });
    }
  }
};
</script>

<style scoped lang="scss">
.ivu-input-number {
  width: -webkit-fill-available;
}

.row_click {
  cursor: pointer;
  color: rgb(50, 113, 240) !important;
}
</style>
